package com.zzyl.controller;


import com.github.pagehelper.Page;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Reader;
import java.util.List;

/**
 * @Author: Learner
 * @Version: 1.0
 */
@Api(tags = "护理等级")
@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController {


    @Autowired
    private NursingLevelService nursingLevelServic;

    /*
     * @Date 2024/6/11 17:10
     *查询所有护理等级
     */

    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> getListAll() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelServic.getListAll();
        return success(nursingLevelVos);
    }

    /*
     * @Date 2024/6/11 17:44
     *新增
     */
    @PostMapping("/insert")
    @ApiOperation("新增")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelServic.addNursingLevel(nursingLevelDto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "护理项目名称", required = false, dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "Integer")
    })
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(String name, Integer status, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResponse<NursingLevelVo> nursingLevelVos = nursingLevelServic.listByPage(name, status, pageNum, pageSize);
        return success(nursingLevelVos);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据Id查询")
    public ResponseResult getById(@PathVariable long id) {
        NursingLevelVo nursingLevelVo = nursingLevelServic.getById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改")
    public ResponseResult updateNursringLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelServic.updateNursringLevel(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    public ResponseResult delById(@PathVariable long id){
        nursingLevelServic.delById(id);
        return success();

    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")

    public ResponseResult updateStatus(@ApiParam("护理等级Id") @PathVariable long id ,@ApiParam("状态") @PathVariable Integer status){
        nursingLevelServic.updateStatus(id,status);
        return success();
    }

}